//
//  PublicFunction.m
//  MobiProject
//
//  Created by 阔 李 on 16/10/23.
//  Copyright © 2016年 yxnzb. All rights reserved.
//

#import "PublicFunction.h"


@implementation PublicFunction

//判断设备系统版本是否为IOS7之后版本
+ (BOOL)isIOS7OrLater{
    return [[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0;
}
//保存配置信息
+ (BOOL) saveConfig:(id)value forKey:(NSString*) key{
    
    NSUserDefaults* info = [NSUserDefaults standardUserDefaults];
    [info setObject:value forKey:key];
    
    return [info synchronize];
}

//读取配置信息
+ (id) getConfigWithKey:(NSString*) key{
    
    NSUserDefaults* info = [NSUserDefaults standardUserDefaults];
    
    return [info objectForKey:key];
}
//移除配置信息
+ (void) removeConfigWithKey:(NSString*) key{
    
    NSUserDefaults* info = [NSUserDefaults standardUserDefaults];
    [info removeObjectForKey:key];
    [info synchronize];
}

// 弹出系统警告框
+ (UIAlertView *)showAlert:(NSString *)title message:(NSString *)msg duration:(NSTimeInterval)time{
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
                                                    message:msg
                                                   delegate:nil
                                          cancelButtonTitle:nil
                                          otherButtonTitles:nil];
    
    
    [alert show];
    
    
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    UIView *showview =  [[UIView alloc]init];
    showview.backgroundColor = [UIColor cyanColor];
    showview.frame = CGRectMake(1, 1, 1, 1);
    showview.alpha = 1.0f;
    [window addSubview:showview];
    
    [UIView animateWithDuration:1.0f animations:^{
        showview.alpha=0;
    } completion:^(BOOL finished) {
        if (finished) {
            [showview removeFromSuperview];
            [alert dismissWithClickedButtonIndex:0 animated:YES];
        }
    }];
    
    return alert;
}

+ (UIAlertController *)showAlert:(NSString *)title Mesasge:(NSString *)message viewController:(UIViewController *)vc completion:(void (^)(BOOL finished))completion{
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    [vc presentViewController:alertController animated:YES completion:^{
        
        UIWindow * window = [UIApplication sharedApplication].keyWindow;
        UIView *showview =  [[UIView alloc]init];
        showview.backgroundColor = [UIColor cyanColor];
        showview.frame = CGRectMake(1, 1, 1, 1);
        showview.alpha = 1.0f;
        [window addSubview:showview];
        
        [UIView animateWithDuration:1 animations:^{
            showview.alpha = 0;
        } completion:^(BOOL finished) {
            if (finished) {
                
                [alertController dismissViewControllerAnimated:YES completion:nil];
            }
        }];
        
    }];
    
    return alertController;
}


@end
